package com.ds.robot.assistant.controller;

import com.ds.robot.assistant.common.R;
import com.ds.robot.assistant.component.MessageSender;
import com.ds.robot.assistant.entity.TargetOkrEntity;
import com.ds.robot.assistant.enums.Env;
import com.ds.robot.assistant.service.TargetAchievementService;
import com.ds.robot.assistant.service.TargetOkrService;
import com.ds.robot.assistant.vo.OkrVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@RestController
@RequestMapping("/okr")
@Slf4j
public class OkrController {

    @Value("${app.quarter:2024H2}")
    private String quarter;

    @Autowired
    private TargetAchievementService achievementService;

    @Autowired
    private TargetOkrService okrService;

    @Autowired
    private MessageSender messageSender;

    @GetMapping("/getOkrList")
    public R getOkrList() {
        List<TargetOkrEntity> okrEntityList = okrService.list();
        return R.ok().put("data", okrEntityList);
    }

    @GetMapping("/getDetail")
    public R getOkrDetail() {
        List<OkrVO> voList = okrService.queryOrkList(quarter);
        return R.ok().put("data", voList);
    }

    @GetMapping("/getOkrReport")
    public R getOkrReport() {
        String reportMessage = okrService.getOkrReportMessage(quarter);
        // log.info("查询OKR report message: {}", reportMessage);
        messageSender.sendMessage(reportMessage, Env.TEST);

        return R.ok().put("data", reportMessage);
    }

    @GetMapping("/getOkrReportProd")
    public R getOkrReportProd() {
        String reportMessage = okrService.getOkrReportMessage(quarter);
        log.info("查询 PROD OKR report message: {}", reportMessage);
        messageSender.sendMessage(reportMessage, Env.PROD);
        return R.ok().put("data", reportMessage);
    }

    @GetMapping("/checkAndProcess")
    public R checkAndProcessData() {
        achievementService.checkAndProcessData();
        return R.ok();
    }

}
